//
// This file contains the definitions of objects used along in the game.
//
//   This file is part of Linux Legends.
//
//   Linux Legends is free software: you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#include <iostream>
#include <string>
#include "creatures.h"

// The creature is the basic fighting unit in the game.
Creature::Creature(int atk, int hp, int def, int xp):
    max_attack(atk), health(hp), defense(def), experience(xp)
{ }

int Creature::attack()
{
    return max_attack;
}

bool Creature::is_dead()
{
    return (health < 0);
}

// Monster definitions:
Monster::Monster(int atk, int hp, int def, int xp, std::string nm):
    Creature(atk, hp, def, xp), name(nm)
{
    std::cout << "A " << name << " appears!\n";
}

void Monster::defend(int incoming)
{
    if (incoming >= defense) {
        int damage = incoming - defense;
        health -= damage;
        std::cout << name << " loses " << damage << " hp.\n"; 
    }
    else {
        std::cout << name << " defends your attack!\n";
    }
}

int Monster::yield_xp()
{
    return experience;
}

// Player definitions
Player::Player(int atk, int hp, int def, int xp, std::string eq):
    Creature(atk, hp, def, xp), weapon(eq)
{
    std::cout << "A new player steps in the field.\n";
}

void Player::defend(int incoming)
{
    if (incoming >= defense) {
        int damage = incoming - defense;
        health -= damage;
        std::cout << "You lose " << damage << " hp.\n"; 
    }
    else {
        std::cout << "You defended the attack!\n";
    }
}

void Player::get_xp(int xp)
{
    experience += xp;
    std::cout << "You receive " << xp << "xp, and now have "
        << experience << " experience.\n";
}
